`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    17:32:22 11/26/2012 
// Design Name: 
// Module Name:    TOP_HDL 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module TOP_HDL #(parameter WIDTH=16)
(
	input clk_1_x,
	input clk_129_x,
	input clk_1_8_x,
	input clk_32_x,
	input clk_20_x,
	input rst,
	input signed[WIDTH-1:0] in_data,
	output detect

    );
	 
	 wire signed[WIDTH-1:0] downshift_out_r;
	 wire signed[WIDTH-1:0] downshift_out_i;
	 wire signed[WIDTH-1:0] lpf_out_r;
	 wire signed[WIDTH-1:0] lpf_out_i;
	 wire signed[WIDTH-1:0] downsample_out_r;
	 wire signed[WIDTH-1:0] downsample_out_i;
	 wire signed[WIDTH-1:0] corr_out_r;
	 wire signed[WIDTH-1:0] corr_out_i;
	 
	 DOWNSHIFT_BLOCK #(34, 7, 96, WIDTH, 0) B_downshift
	(
		.clk(clk_1_x),
		.rst(rst),
		.in_data(in_data),
		.out_r(downshift_out_r),
		.out_i(downshift_out_i)
    );
	 
	 LPF_BLOCK #(8, 129, WIDTH, 0) B_lpf
	(
		.clk_1_x(clk_1_x),
		.clk_len_x(clk_129_x),
		.rst(rst),
		.in_data_r(downshift_out_r),
		.in_data_i(downshift_out_i),
		.out_r(lpf_out_r),
		.out_i(lpf_out_i)
    );
	 
	 DOWN_SAMPLE_BLOCK #(3, 8, WIDTH) B_downsample
	(
		 .clk(clk_1_x),
		 .rst(rst),
		 .data_in_r(lpf_out_r),
		 .data_in_i(lpf_out_i),
		 .data_out_r(downsample_out_r),
		 .data_out_i(downsample_out_i)
    );
	 
	 HFM_CORR_BLOCK #(8, 256, WIDTH, 0) B_corr
	(
		.clk_r_x(clk_1_8_x),
		.clk_r_len_x(clk_32_x),
		.rst(rst),
		.in_data_r(downsample_out_r),
		.in_data_i(downsample_out_i),
		.out_r(corr_out_r),
		.out_i(corr_out_i)
    );
	 
	 DETECT_BLOCK #(5, 32, 0, 9, 416, 8, 160, 1, 256, WIDTH, 0) B_trig
	(
		.clk_r_x(clk_1_8_x),
		.clk_r_len_x(clk_20_x),
		.rst(rst),
		.in_r(corr_out_r),
		.in_i(corr_out_i),
		.detect(detect)
	 );


endmodule
